<script language="javascript" type="text/javascript">
	$('#checkall').click(function () {
		$(':checkbox').attr('checked', this.checked);
	});
	
	$('#salva').click(function() {
		var res=[];
		$('#res:checked').each(function() {
       res.push($(this).val());
     });
	   var jrole = $('#salva a').attr("href")+"&idmlu="+res;
        $('#tabrest').fadeOut(1000,function(){$('#tabrest').load(jrole,'',$('#tabrest').fadeIn(1000))}); 
		return false;
    }); 

    </script>

<?php	
require("../Connections/mlu.php");
	
	if (isset($_GET['idc']) && !isset($idc))
	{
		$idc=$_GET['idc'];
		$myCheck = $_GET['idmlu']; 
		$pieces = explode(",", $myCheck);
		foreach ($pieces as $key => $value) { 
			$query_Recordset1riclibri = "update depositati set datares=date(now()) where idmlu=$value";
			$Recordset1riclibri = mysql_query($query_Recordset1riclibri, $mlu) or die(mysql_error());
		}
		
	}
	$query_Recordset1riclibri = "select round(sum(prezzo/2),2) as prezzotot from depositati join carrelli using (idmlu) where idcliente=$idc and datares=0";
	$Recordset1riclibri = mysql_query($query_Recordset1riclibri, $mlu) or die(mysql_error());
	$row_Recordset1 = mysql_fetch_assoc($Recordset1riclibri);
	$total=mysql_num_rows($Recordset1riclibri);	

	
?>



<div id="tabrest">
<h1>da restituire: <?php echo $row_Recordset1['prezzotot']; ?> </h1>
<?php

	
	$query_Recordset1riclibri = "select idmlu,titolo,depositati.prezzo from depositati join libri using (idlibro) where idcliente=$idc and idmlu not in (select idmlu from carrelli) and datares=0";
	$Recordset1riclibri = mysql_query($query_Recordset1riclibri, $mlu) or die(mysql_error());
	$row_Recordset1 = mysql_fetch_assoc($Recordset1riclibri);
	$total=mysql_num_rows($Recordset1riclibri);
?>
<h1 align="center">Libri da restituire</h1>
<table border="1" align="center" class="tabellalibri">
  <tr>
    <td>&nbsp;</td>
    <td>ID</td>
    <td>titolo</td>
    <td>prezzo</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><input type="checkbox" id="res" value="<?php echo $row_Recordset1['idmlu']; ?>"/> </td>
      <td><?php echo $row_Recordset1['idmlu']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['titolo']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['prezzo']; ?>&nbsp; </td>
    </tr>
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1riclibri)); ?>
</table>
<input type="checkbox" id="checkall"> Seleziona tutto <br />
<p> Totale libri in magazzino: <?php echo $total; ?> </p>

<button id="salva"><a href="restituzione/tabellalibrimagazzino.php?idc=<?php echo $idc; ?>">salva</a></button>


<?php include ("tabellalibrirestituiti.php"); ?>
</div>